package com.kc.web.controller.business;

import com.kc.business.domain.vo.KcUserStatisticsVO;
import com.kc.business.service.IBizUserStatisticsService;
import com.kc.common.core.domain.AjaxResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName BizUserStatisticsController
 * @Description 用户统计controller
 * @Author wangdongliang
 * @Date 2021/5/17 10:47
 */
@RestController
@RequestMapping("/business/userStatistics")
@Slf4j
public class BizUserStatisticsController {

    @Resource
    private IBizUserStatisticsService userStatisticsService;

    /**
     * 按照区域统计用户
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:userStatistics:getNumByArea')")
    @GetMapping(value = "/getNumByArea")
    public AjaxResult getNumByArea(){
        return AjaxResult.success(userStatisticsService.getNumByArea());
    }
    /**
     * 按照区域统计用户(比例)
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:userStatistics:getNumByAreaRatio')")
    @GetMapping(value = "/getNumByAreaRatio")
    public AjaxResult getNumByAreaRatio(){
        return AjaxResult.success(userStatisticsService.getNumByAreaRatio());
    }
    /**
     * 按照等级统计用户
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:userStatistics:getNumByLevel')")
    @GetMapping(value = "/getNumByLevel")
    public AjaxResult getNumByLevel(){
        return AjaxResult.success(userStatisticsService.getNumByLevel());
    }
    /**
     * 按照认证状态统计用户
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:userStatistics:getNumByAuthStatus')")
    @GetMapping(value = "/getNumByAuthStatus")
    public AjaxResult getNumByAuthStatus(){
        List<KcUserStatisticsVO> userStatisticsVOS = new ArrayList<>();
        //全部认证
        Integer num = userStatisticsService.getNumByAuthStatus(1,1);
        userStatisticsVOS.add(new KcUserStatisticsVO("全部认证",num.toString()));
        //未实名和人脸认证
        num = userStatisticsService.getNumByAuthStatus(0,-2);
        userStatisticsVOS.add(new KcUserStatisticsVO("未实名和人脸认证",num.toString()));
        //仅实名认证
        num = userStatisticsService.getNumByAuthStatus(1,-2);
        userStatisticsVOS.add(new KcUserStatisticsVO("仅实名认证",num.toString()));
        return AjaxResult.success(userStatisticsVOS);
    }

    /**
     * 按照是否有分销统计用户
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:userStatistics:getNumByLowerLevel')")
    @GetMapping(value = "/getNumByLowerLevel")
    public AjaxResult getNumByLowerLevel(){
        List<KcUserStatisticsVO> userStatisticsVOS = new ArrayList<>();
        //有分销
        Integer num = userStatisticsService.getNumByLowerLevel(1);
        userStatisticsVOS.add(new KcUserStatisticsVO("有分销",num.toString()));
        //无分销
        num = userStatisticsService.getNumByLowerLevel(0);
        userStatisticsVOS.add(new KcUserStatisticsVO("无分销",num.toString()));
        return AjaxResult.success(userStatisticsVOS);
    }

    /**
     * 按照年龄区间统计用户
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:userStatistics:getNumByAgeSection')")
    @GetMapping(value = "/getNumByAgeSection")
    public AjaxResult getNumByAgeSection(){
        return AjaxResult.success(userStatisticsService.getNumByAgeSection());
    }
    /**
     * 按照性别统计用户
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:userStatistics:getNumBySex')")
    @GetMapping(value = "/getNumBySex")
    public AjaxResult getNumBySex(){
        return AjaxResult.success(userStatisticsService.getNumBySex());
    }

}
